package main;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnTest {
	public static void main(String[] args) {
		Connection conn = null;
		Statement statement = null;
		ResultSet resultSet = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager.getConnection(
					"jdbc:oracle:thin:@127.0.0.1:1521:orcl", "scott", "tiger");
			statement = conn.createStatement();
			resultSet = statement.executeQuery("SELECT empno,ename from emp");
			while (resultSet.next()) {
				System.out.println(resultSet.getString("empno") + ", "
						+ resultSet.getString("ename"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				// conn.close();
				resultSet.close();
				statement.close();
				conn.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
